package com.c.ctgproject.wiget.dialog

import android.app.Dialog
import android.content.Context
import android.view.Gravity
import android.view.WindowManager
import android.widget.*

import com.c.ctgproject.R
import com.c.ctgproject.entity.GroupEntity
import org.jetbrains.anko.windowManager

//选择商友分组弹框
class ChooseFriendGroupDialog : Dialog {
    var mChooseGroupLL: LinearLayout? = null
    var mGroupNameET: TextView? = null
    var mConfirmBTN: Button? = null
    var mCancelBTN: Button? = null
    var mCancelIV: ImageView? = null
    var selectPostion = -1

    constructor(context: Context, themeStyle: Int) : super(context, themeStyle) {
        initView()
    }

    private fun initView() {
        setContentView(R.layout.choose_friend_group_dialog)
//        mLabelET=findViewById(R.id.mLabelET)
//        mConfirmTV=findViewById(R.id.mConfirmTV)
//        mCancelTV=findViewById(R.id.mCancelTV)
//        mGroupNameTV=findViewById(R.id.mGroupNameTV)
//        mChooseGroupLL = findViewById(R.id.mChooseGroupLL)
//        mGroupNameET = findViewById(R.id.mGroupNameET)
//        mConfirmBTN = findViewById(R.id.mConfirmBTN)
//        mCancelBTN = findViewById(R.id.mCancelBTN)
//        mCancelIV = findViewById(R.id.mCancelIV)


    }


    class Builder(val context: Context) {
        var addLabelListener: CallBack? = null

        var groupList = ArrayList<GroupEntity.Data.DefGroup>()
        fun setGroupList(list: List<GroupEntity.Data.DefGroup>): Builder {

            groupList?.addAll(list)

            return this
        }

        fun setChangeGroupClickListener(listener: CallBack): Builder {
            this.addLabelListener = listener
            return this
        }

        fun create(): ChooseFriendGroupDialog {
            val dialog = ChooseFriendGroupDialog(context, R.style.CommonDialog)
            dialog.window?.setGravity(Gravity.CENTER)
            //设置不遮挡后面
            //dialog.window?.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
            //获得window窗口的属性
            val lp = dialog.window?.attributes
            //设置窗口宽度为充满全屏
            //dialog.dialog_phone?.text = phonetext
            val m: WindowManager = context.windowManager
            val display = m.defaultDisplay
            lp?.width = display.width / 4 * 3
            lp?.height = WindowManager.LayoutParams.WRAP_CONTENT
            dialog.mConfirmBTN?.setOnClickListener {
                if (dialog.selectPostion == -1) {
                    //context.showToast("请先选择标签组")
                } else {
                    addLabelListener?.selectLabel(groupList[dialog.selectPostion])
                    dialog.dismiss()
                }
            }
            dialog.mCancelBTN?.setOnClickListener {
                dialog.dismiss()
            }
            val stringList = ArrayList<String>()
            groupList.forEach {
                //stringList.add(it.groupName.handlerNull())
            }
            dialog.mChooseGroupLL?.setOnClickListener {
                // groupList?.let { it1 ->  }
                groupList?.let { it1 ->
//                    StringChooseDialog.Builder(context).setSelectListener(dialog).setList(
//                        stringList
//                    ).create().show()
                }
            }
            //控件与onclick绑定
//            if (cancelListener != null) {
//                dialog.tvDialogCancel?.setOnClickListener { v -> cancelListener!!.onClick(dialog) }
//            }
//            if (confirmListener != null) {
//                dialog.btDialogConfirm?.setOnClickListener { v -> confirmListener!!.onClick(dialog) }
//            }
            return dialog
        }


    }

    interface CallBack {
        fun selectLabel(data: GroupEntity.Data.DefGroup)
    }




}